package com.pqc.tbk.dao.order;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.pqc.tbk.dao.BaseDaoSupport;
import com.pqc.tbk.entity.order.Order;
import com.pqc.tbk.utils.Pager;

/**
 * 
 * @author long, create on 2012-7-19 下午2:04:59
 * 
 */
@Repository
public class OrderDaoImpl extends BaseDaoSupport<Order> implements OrderDao {

	private final String GETCOUNT = "select count(*) from Order where uid=";
	private final String CONDITION = "from Order where 1=1 ";

	@Override
	public Pager<Order> getOrders(final Pager<Order> pager, final String search) {
		final String hql = CONDITION + search;
		final Query query = em.createQuery(hql);
		query.setFirstResult((int) pager.getOffSet());
		query.setMaxResults((int) pager.getPageSize());
		// 查询出结果 组装pager对象
		pager.setContent(query.getResultList());
		return pager;
	}

	@Override
	public Long getCountByUID(final long uid) {
		return (Long) em.createQuery(GETCOUNT + uid).getSingleResult();
	}

}
